
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
	<HEAD>
		<title>
			Mobile Developers Online Group:  - Lightweight&nbsp;Logging&nbsp;with&nbsp;TextLogger</title>
		<LINK href="favicon.ico" type="image/x-icon" rel="icon">
		<LINK href="favicon.ico" type="image/x-icon" rel="shortcut icon">
		
			<META content="logging, files, text,Developer, Windows, Mobile, Smartphone, Smart, Phone, Device, Pocket PC, embedded, game, mappoint, mls, dot, net, .net, visual, studio, evb, evc, ce" name="keywords">
		
			<META content="TextLogger - Lightweight Logging Class for CF Apps, by Chris Howlett at Mobidogs" name="description">
		
		<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
		<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
		<meta content="JavaScript" name="vs_defaultClientScript">
		<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
		<style>DIV.MainDiv A { TEXT-DECORATION: none }
	DIV.MainDiv A:unknown { COLOR: #087bef }
	DIV.MainDiv A:link { COLOR: #087bef }
	DIV.MainDiv A:visited { COLOR: #087bef }
	DIV.MainDiv A:hover { TEXT-DECORATION: underline }
	DIV.MainMenuRed A { TEXT-DECORATION: none }
	DIV.MainMenuRed A:unknown { COLOR: #cc3300 }
	DIV.MainMenuRed A:link { COLOR: #cc3300 }
	DIV.MainMenuRed A:visited { COLOR: #cc3300 }
	DIV.MainMenuRed A:hover { COLOR: #ffffff; TEXT-DECORATION: none }
	DIV.MainMenuBlue A { TEXT-DECORATION: none }
	DIV.MainMenuBlue A:unknown { COLOR: #006699 }
	DIV.MainMenuBlue A:link { COLOR: #006699 }
	DIV.MainMenuBlue A:visited { COLOR: #006699 }
	DIV.MainMenuBlue A:hover { COLOR: #ffffff; TEXT-DECORATION: none }
		</style>
		
			<STYLE type="text/css">BODY {
	FONT-SIZE: x-small; BACKGROUND-IMAGE: url(/images/border_blue2.gif); BACKGROUND-REPEAT: repeat-y; FONT-FAMILY: Arial; BACKGROUND-COLOR: white
}
			</STYLE>
		
	</HEAD>
	<body leftMargin="0" topMargin="0" rightMargin="0">
		<div class="MainDiv" id="MainDiv">
			<form name="Form1" method="post" action="Detail.aspx?Detail=15" id="Form1">
<input type="hidden" name="__VIEWSTATE" value="dDw0OTk2ODg4Njs7bDxVY1NpdGVYTGluazE6aW1nU2l0ZVhMaW5rOz4+AMAqwf4wBA1vIFP7v8hl8ZkLG1k=" />

				<TABLE id="Table1" height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0">
					<TR>
						<TD vAlign="top" colSpan="3" height="1%">
<TABLE id="tblBanner" height="1%" cellSpacing="0" cellPadding="0" width="100%" border="0">
	<TR>
		<TD style="WIDTH: 452px" vAlign="top" height="1%"><a href="http://www.mobidogs.com"><img id="UcBanner1_imgLogo" src="/Images/MobiLogo.gif" alt="" align="Top" border="0" /></a><img id="UcBanner1_imgBannerMiddle" src="/Images/cellman.gif" alt="" align="AbsBottom" border="0" /></TD>
		<TD height="1%">
			<img id="UcBanner1_imgBannerRight" src="/Images/mbanner_right.jpg" alt="" align="Right" border="0" /></TD>
	</TR>
</TABLE>
</TD>
					</TR>
					<TR>
						<TD vAlign="top" colSpan="3" height="1%">
<P>
	<TABLE id="Table1" cellSpacing="0" cellPadding="0" width="100%" border="0">
		<TR>
			<TD background='/Images/sepline_blue.gif' colSpan='3' height='6'></TD>
		</TR>
	</TABLE>
</P>
</TD>
					</TR>
					<TR>
						<TD vAlign="top" width="10%"><div id='MainMenuBlue' class='MainMenuBlue'>
<table height="1%" cellSpacing="0" cellPadding="0" width="133" border="0">
	<TBODY>
		<tr>
			<td vAlign="top">
						<table cellSpacing="0" cellPadding="0" width="100%" border="0">
					
						<tr>
							<td width="1"><img src='/Images/nav_left_blue.gif'></td>
							<td background='/Images/nav_mid_blue.gif'>
								<a href='/SmartPhone/TPage.aspx'><img src='/Images/bluearrow.gif' border=0>
								</a>&nbsp;
							</td>
							<td background='/Images/nav_mid_blue.gif' >
								<a href='/SmartPhone/TPage.aspx'><font size="2"><b>
											SmartPhone
										</b></font></a>
							</td>
							<td width="1"><img src='/Images/nav_right_blue.gif'></td>
						</tr>
					
						<tr>
							<td width="1"><img src='/Images/nav_left_blue.gif'></td>
							<td background='/Images/nav_mid_blue.gif'>
								<a href='/PocketPC/TPage.aspx'><img src='/Images/bluearrow.gif' border=0>
								</a>&nbsp;
							</td>
							<td background='/Images/nav_mid_blue.gif' >
								<a href='/PocketPC/TPage.aspx'><font size="2"><b>
											Pocket PC
										</b></font></a>
							</td>
							<td width="1"><img src='/Images/nav_right_blue.gif'></td>
						</tr>
					
						<tr>
							<td width="1"><img src='/Images/nav_left_blue.gif'></td>
							<td background='/Images/nav_mid_blue.gif'>
								<a href='/Embedded/TPage.aspx'><img src='/Images/bluearrow.gif' border=0>
								</a>&nbsp;
							</td>
							<td background='/Images/nav_mid_blue.gif' >
								<a href='/Embedded/TPage.aspx'><font size="2"><b>
											Embedded
										</b></font></a>
							</td>
							<td width="1"><img src='/Images/nav_right_blue.gif'></td>
						</tr>
					
						<tr>
							<td width="1"><img src='/Images/nav_left_blue.gif'></td>
							<td background='/Images/nav_mid_blue.gif'>
								<a href='/GameDev/TPage.aspx'><img src='/Images/bluearrow.gif' border=0>
								</a>&nbsp;
							</td>
							<td background='/Images/nav_mid_blue.gif' >
								<a href='/GameDev/TPage.aspx'><font size="2"><b>
											Game Dev
										</b></font></a>
							</td>
							<td width="1"><img src='/Images/nav_right_blue.gif'></td>
						</tr>
					
						<tr>
							<td width="1"><img src='/Images/nav_left_blue.gif'></td>
							<td background='/Images/nav_mid_blue.gif'>
								<a href='/MapPoint/TPage.aspx'><img src='/Images/bluearrow.gif' border=0>
								</a>&nbsp;
							</td>
							<td background='/Images/nav_mid_blue.gif' >
								<a href='/MapPoint/TPage.aspx'><font size="2"><b>
											MapPoint
										</b></font></a>
							</td>
							<td width="1"><img src='/Images/nav_right_blue.gif'></td>
						</tr>
					
						<tr>
							<td width="1"><img src='/Images/nav_left_blue.gif'></td>
							<td background='/Images/nav_mid_blue.gif'>
								<a href='/TabletPC/TPage.aspx'><img src='/Images/bluearrow.gif' border=0>
								</a>&nbsp;
							</td>
							<td background='/Images/nav_mid_blue.gif' >
								<a href='/TabletPC/TPage.aspx'><font size="2"><b>
											Tablet PC
										</b></font></a>
							</td>
							<td width="1"><img src='/Images/nav_right_blue.gif'></td>
						</tr>
					
						<tr>
							<td width="1"><img src='/Images/nav_left_blue.gif'></td>
							<td background='/Images/nav_mid_blue.gif'>
								<a href='/DotNetMF/Tpage.aspx'><img src='/Images/bluearrow.gif' border=0>
								</a>&nbsp;
							</td>
							<td background='/Images/nav_mid_blue.gif' >
								<a href='/DotNetMF/Tpage.aspx'><font size="2"><b>
											.Net MF
										</b></font></a>
							</td>
							<td width="1"><img src='/Images/nav_right_blue.gif'></td>
						</tr>
					
						<tr>
							<td width="1"><img src='/Images/nav_left_blue.gif'></td>
							<td background='/Images/nav_mid_blue.gif'>
								<a href='/LPage51.aspx'><img src='/Images/bluearrow.gif' border=0>
								</a>&nbsp;
							</td>
							<td background='/Images/nav_mid_blue.gif' >
								<a href='/LPage51.aspx'><font size="2"><b>
											Job Ops
										</b></font></a>
							</td>
							<td width="1"><img src='/Images/nav_right_blue.gif'></td>
						</tr>
					
						<tr>
							<td width="1"><img src='/Images/nav_left_blue.gif'></td>
							<td background='/Images/nav_mid_blue.gif'>
								<a href='/DPage4.aspx'><img src='/Images/bluearrow.gif' border=0>
								</a>&nbsp;
							</td>
							<td background='/Images/nav_mid_blue.gif' >
								<a href='/DPage4.aspx'><font size="2"><b>
											Contact Us
										</b></font></a>
							</td>
							<td width="1"><img src='/Images/nav_right_blue.gif'></td>
						</tr>
					
						<tr>
							<td width="1"><img src='/Images/nav_left_blue.gif'></td>
							<td background='/Images/nav_mid_blue.gif'>
								<a href='/DPage1.aspx'><img src='/Images/bluearrow.gif' border=0>
								</a>&nbsp;
							</td>
							<td background='/Images/nav_mid_blue.gif' >
								<a href='/DPage1.aspx'><font size="2"><b>
											About Us
										</b></font></a>
							</td>
							<td width="1"><img src='/Images/nav_right_blue.gif'></td>
						</tr>
					
						<tr>
							<td width="1"><img src='/Images/nav_left_blue.gif'></td>
							<td background='/Images/nav_mid_blue.gif'>
								<a href='/DPage7.aspx'><img src='/Images/bluearrow.gif' border=0>
								</a>&nbsp;
							</td>
							<td background='/Images/nav_mid_blue.gif' >
								<a href='/DPage7.aspx'><font size="2"><b>
											Subscribe
										</b></font></a>
							</td>
							<td width="1"><img src='/Images/nav_right_blue.gif'></td>
						</tr>
					
</table>
</TD></TR></TBODY></TABLE>

<DIV></DIV>
<BR>
							
<table cellSpacing="0" cellPadding="6" width="100%" border="0" >
	<tr>
		
		<td align="Left">
				
		<script type="text/javascript"><!--
google_ad_client = "pub-6530575668627523";
google_alternate_color = "FFC600";
google_ad_width = 120;
google_ad_height = 600;
google_ad_format = "120x600_as";
google_ad_channel ="1624290838";
google_color_border = "006699";
google_color_bg = "FFC600";
google_color_link = "006699";
google_color_url = "0000FF";
google_color_text = "8B4513";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></td>
	</tr>
</table>


							
<table cellSpacing="0" cellPadding="6" width="100%" border="0" >
	<tr>
		
    <TD align=Left>
				
		<A href="/OBELE.aspx?ID=27" target=_blank> 
		
		<img id="UcBannerAd1_Image1" src="/images/adMEDC2006120x90.gif" alt="Register for MEDC" border="0" />
		</A>
</TD>
	</tr>
</table>
</TD>
						<TD vAlign="top">
							<table height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0">
								<tr>
									<td height="1%">
<table width="100%">
	<TBODY>
		<tr>
			<td align="left" valign="top">
				
						<table border="0" cellSpacing="0" cellPadding="0" height="100%">
							<tr>
					
					<TD valign='top' align='left' width='1%' height='1%'>&nbsp;>&nbsp;<a href='/default.aspx'><font size=2 face='Arial'>Home</font></a>&nbsp;</TD>
					<TD valign='top' align='left' width='1%' height='1%'>&nbsp;>&nbsp;<b><font size=2 face='Arial'>Lightweight&nbsp;Logging&nbsp;with&nbsp;TextLogger</font></b>&nbsp;</TD>
						<td width="99%"></td>
		</tr>
</table>
</TD></TR></TBODY></TABLE>
</td>
								</tr>
								<tr>
									<td vAlign="top">
										<table height="100%" width="100%">
											<tr>
												<td vAlign="top" height="99%">
													<P>
<TABLE id="DetailBody" cellSpacing="5" cellPadding="5" width="100%" border="0">
	<TR>
		<TD vAlign="top" colSpan="3"><font color="#006699" size="3"><b>Lightweight Logging with TextLogger</b></font><br>
			<font size="2">
				By: <A href='/DPage14.aspx'>Chris Howlett</a></font><br>
			<font size="2">
				<br>
<img border="0" src=http://mobidogs.com/Images/logbook.jpg align=left>
<font size=4>
<b>Background</b>
</font>
<P>Applications need to log. Important reasons for logging are to record errors 
and to measure performance. The desktop framework provides developers with 
extensive logging facilities and the Microsoft Logging Application Block shines 
as a very high-powered (if complex) orchestration of those facilities. However, 
there isn't much for the Compact Framework. We don't even have an Event Log. 
Now, there is a Debug class with some machinery for directing log messages - 
i.e. help in directing where messages go. However, for CF apps I'm satisfied 
logging to text files, so this Debug class machinery isn't helpful to me. And we 
can't forget the very excellent <A 
href=http://mobidogs.com/obele.aspx?id=25 target=blank>log4net</A>, which has a CF 
implementation. I wanted something a lot lighter than log4net though; something 
that doesn't need a manual; something that is very easy to use and very fast. So 
I wrote TextLogger. This article describes TextLogger and tells you how to 
download it, including source. TextLogger is free.</P>
<H3>TextLogger Features</H3>
<P>TextLogger is a class that provides simple lightweight logging facilities for 
Compact Framework applications. TextLogger's features include 
<img border="0" src=http://mobidogs.com/Images/featherpen.jpg align=right>
<UL>
<LI>Easy to use. You can call TextLogger's static Log method without 
instantiating any objects. That is, you can log "out of the box" without having 
to do any initialization or configuration. 
<LI>Log messages are time-stamped to hundredths of a second. This is useful when 
you are tracing events for performance analysis. For example, I've found this 
very helpful in optimizing algorithms for redrawing custom data grids, where 
timings to the nearest second (the best that CF does, out of the box) aren't 
good enough. 
<LI>Log files are managed automatically. TextLogger writes into a different file 
each day and keeps only the most recent seven daily log files. TextLogger writes 
these files into the system temporary directory (usually \Temp). 
<LI>You can have your apps log to different files if you want. TextLogger 
creates log file names from a prefix and the date. An application can change the 
prefix that TextLogger uses, by setting its Prefix property. 
<LI>You can enable and disable logging at run-time by setting TextLogger's 
Enabled property. 
<LI>You can make your own trade-off between how low the logging overhead is and 
how up-to-date the log file is at any point in time. That is, you can control 
when the log file's buffers are flushed. You choose one of three modes 
<UL>
<LI>AutoClose (default). The file is opened and closed for every log message. It 
is always up-to-date in the file system, and it can usually be read without 
collision by other applications. These other applications might include text 
editors, or the ActiveSync explorer, which you might use to copy the log from 
your device to the desktop for analysis. 
<LI>AutoFlush. The file is opened as needed and is not closed by TextLogger 
unless the application requests it. The log file stream is flushed after each 
log record is written. 
<LI>Manual. The file is opened as needed and is not closed by TextLogger unless 
the application requests it. The log file stream is not flushed unless the 
Application requests it. </LI></UL>
<br>
As you would expect, AutoClose is the slowest 
and Manual is the fastest. On an iPAQ 2200, with AutoClose the average time to 
log a short message with one string parameter to be formatted is around 10.5 
milliseconds. The time for AutoFlush is around 4.5 ms. The time for Manual is 
around 4.0 ms. For normal logging, AutoClose is easiest and most robust. You 
should only consider AutoFlush and Manual if you need very fine performance 
measurements with many messages per second. </LI></UL>

<table border=0 >
<tr valign=top>
<td>
<img border="0" src=http://mobidogs.com/Images/logends2.jpg align=left >
</td>
<td valign=top>
<H3>Example</H3>
<font size=2>
You log a message using formatting, just like the framework WriteLine 
functions.
<br>
For example 
</font>
<br><br>
<font size=3><b>Visual Basic .NET</b></font>
<font size=3><PRE><CODE>	Class ConsoleApp
		Sub Main(ByVal args() As String)
			TextLogger.Log(&quot;ConsoleApp starting, {0}.&quot;, &quot;hello&quot;)
		End Sub
	End Class</CODE></PRE></font>

<font size=3><b>Visual C#</b></font>
<font size=3><PRE><CODE>	class ConsoleApp
	{
		[STAThread]
		static void Main(string[] args)
		{
			TextLogger.Log(&quot;ConsoleApp starting, {0}.&quot;, &quot;hello&quot;);
		}
	}
</CODE></PRE></font>
<br>
<font size=2>
The message logged by the above code might look like this 
</font>
<font size=3><PRE><CODE>	11:36:01.47 ConsoleApp starting, hello.
</CODE></PRE></font>
</td>
</tr>
</table>
<H3>Downloading TextLogger</H3>
Download it <A href="http://www.mobidogs.com/samples/textlogger.msi">here</A>.
<br><br>
<img border="0" src=http://mobidogs.com/Images/logs.jpg align=right>
The distribution includes the C# class library that contains TextLogger, plus 
an example that illustrates logging and also allows you to see and measure 
precisely the overheads associated with the three different flush methods.
 The example is provided as two projects, one in C# and one in VB.NET. All source is 
included.
<br><br>
<TABLE id="Table1" cellSpacing="1" cellPadding="1" border="0" align="left">
	<tr>
		<td colspan="2"><hr>
		</td>
		<td></td>
	</tr>
	<TR>
		<TD width="10%">
			<font size="2"><i>See&nbsp;profile&nbsp;of:</i></font></TD>
		<TD width="1%">
			
				<A href="/DPage14.aspx">
			<b><span id="_ctl0_UcProfileTagLine1_lblName">Chris&nbsp;Howlett</span></b></A></TD>
		<TD></TD>
	</TR>
	<TR>
		<TD></TD>
		<TD><font size="2"><span id="_ctl0_UcProfileTagLine1_lblCompany">Howlett&nbsp;Approach</span></font></TD>
		<TD></TD>
	</TR>
</TABLE>
</font></TD>
		</FONT></TR>
</TABLE>
<br>
														</P>
												</td>
											</tr>
											<tr>
												<td>
													
<table cellSpacing="0" cellPadding="6" width="100%" border="0" >
	<tr>
		
    <TD align=Center>
				
		
		
		</A>
</TD>
	</tr>
</table>
<BR>
													
<table cellSpacing="0" cellPadding="6" width="100%" border="0" >
	<tr>
		
		<td align="Center">
				
		</td>
	</tr>
</table>


												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
							&gt;
						</TD>
						<TD vAlign="top" width="10%">
							<P>
<TABLE id="Table1" cellSpacing="0" cellPadding="0" width="100%" border="0">
	<TR>
		<TD>
			<!-- SiteSearch Google -->

<table border="0" bgcolor="#ffffff">
<tr><td nowrap="nowrap" valign="top" align="left" height="32">
<a href="http://www.google.com/">
<img src="http://www.google.com/logos/Logo_25wht.gif"
border="0" alt="Google"></img></a>
<br/>
<input type="hidden" name="domains" value="www.mobidogs.com"></input>
<input type="text" name="q" size="20" maxlength="255" value=""></input>
<input type="submit" name="sa" value="Search"></input>
</td></tr>
<tr>
<td nowrap="nowrap">
<font size="-1" color="#000000">
<input type="radio" name="sitesearch" value=""></input> Web
<input type="radio" name="sitesearch" value="www.mobidogs.com" checked="checked"></input>www.mobidogs.com
</font>&nbsp;&nbsp;
<input type="hidden" name="client" value="pub-6530575668627523"></input>
<input type="hidden" name="forid" value="1"></input>
<input type="hidden" name="channel" value="7883829570"></input>
<input type="hidden" name="ie" value="ISO-8859-1"></input>
<input type="hidden" name="oe" value="ISO-8859-1"></input>
<input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:FFFFFF;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;LH:45;LW:100;L:http://www.mobidogs.com/images/tinymobynb.gif;S:http://www.mobidogs.com;FORID:1;"></input>
<input type="hidden" name="hl" value="en"></input>

</td></tr></table>

<!-- SiteSearch Google --></TD>
	</TR>
</TABLE>


<table width="100%" border="0" cellpadding="0" cellspacing="5">
	<TBODY>
		<tr>
			<td>
				
</TD></TR></TBODY></TABLE>

<table cellSpacing="0" cellPadding="6" width="100%" border="0" >
	<tr>
		
		<td align="Center">
				
		</td>
	</tr>
</table>


								
<table cellSpacing="0" cellPadding="6" width="100%" border="0" >
	<tr>
		
    <TD align=Center>
				
		
		
		</A>
</TD>
	</tr>
</table>
</P>
						</TD>
					</TR>
					<TR>
						<TD vAlign="top" height="1%">
<TABLE id="Table1" cellSpacing="5" cellPadding="0" width="100%" border="0">
	<TR>
		<TD>
			<input type="image" name="UcSiteXLink1:imgSiteXLink" id="UcSiteXLink1_imgSiteXLink" src="/Images/smallvb.gif" alt="" border="0" /></TD>
	</TR>
</TABLE>
</TD>
						<TD vAlign="top" colSpan="2" height="1%">
<TABLE id="Table1" height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0">
	<TR>
		<td width="1%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<TD>
				<HR color="" SIZE="1">
			<font size="1">&nbsp;&nbsp; &nbsp;© 2006
				<a href="http://www.Visualbyte.com" target="_blank">Visual Byte Inc.</a> All 
				rights reserved. </font>
		</TD>
	</TR>
	<TR height="99%">
		<TD width="1%"></TD>
		<TD valign="bottom">
			<P align="right">
				<font size="1">
					Server: Friday, October 27, 2006 7:04:55 PM
				</font>
			</P>
		</TD>
	</TR>
</TABLE>
</TD>
					</TR>
				</TABLE>
			</form>
		</div>
	</body>
</HTML>
